package com.Servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Servlet.Dao.usersEntity;
import com.User.Dao.Record;

/**
 * Servlet implementation class readerToRenewal
 */
@WebServlet("/readerToRenewal")
public class readerToRenewal extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String[] values = request.getParameterValues("checkBook");
		String userSno = request.getParameter("userSno");
		request.setAttribute("userSno", userSno);
		request.setAttribute("flag", "renewalInfo");
		request.setAttribute("renewalFlag", "true");
		if(values != null) {
			for(int i = 0; i < values.length; i++) {
				try {
					usersEntity.renewalToUser(userSno, values[i]);
				} catch (SQLException e) {
					request.setAttribute("renewalFlag", "false");
					System.out.println("The " + i + " book failed");
				}
			}
		}
		request.getRequestDispatcher("Main.jsp").forward(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
